Method and system for storage of data in non-volatile media

ABSTRACT

A system and method for managing the storage of data in non-volatile memory is described. In an aspect, the data may be described by metadata and a transaction log file that are checkpointed from a volatile memory into the non-volatile memory. Actions that take place between the last checkpointing of a metadata segment and log file segment are discovered by scanning the non-volatile memory blocks, taking account of a record of the highest sector in each block that is known to have been recorded. Any later transactions are discovered and used to update the recovered metadata so that the metadata correctly represents the stored data.

This application is a divisional application of, and claims priority to,U.S. Ser. No. 12/273,410, filed on Nov. 18, 2008, which claims thebenefit of U.S. provisional application, Ser. No. 61/003,897, filed onNov. 21, 2007, each of which is incorporated herein by reference;application Ser. No. 12/273,410 is also a continuation-in-part of U.S.application Ser. No. 11,405,083, filed on Apr. 17, 2006, which claimspriority to U.S. provisional application Ser. No. 60/674,189, filed onApr. 21, 2005, and to U.S. provisional application 60/698,626, filed onJul. 11, 2005, and of U.S. application Ser. No. 12/079,364, filed onMar. 26, 2008, which claims priority to U.S. provisional application60/920,737, which was filed on Mar. 29, 2007, each of which isincorporated herein by reference.

TECHNICAL FIELD

This application may relate to the storage of data on volatile andnon-volatile storage media.

BACKGROUND

Non-volatile memory or non-volatile storage (NVS) is useful in computingsystems to store data which needs to be retained for a long period oftime, and retain data integrity after a power loss or other systemfailure event. Examples of non-volatile storage may be magnetic disks,magnetic tape, optical disks, and flash memory. Such memory is alsocalled persistent storage.

Flash memory is an example of NVS that stores information in an array ofsemiconductor memory cells. In a single-level cell (SLC) device, eachcell stores only one bit of information. A recently developed type offlash memory, known as a multi-level cell (MLC) device, can store morethan one bit per cell by choosing between multiple levels of electricalcharge to apply to the cell. Other types of NVS are being developed, andmay be expected to come into use in the future.

Two generic types of flash memory circuits are currently in wide use:NOR and NAND. At present, for large memory systems, NAND flash memory ispreferred. While NOR flash memory permits reading and writing(programming) operations to be performed on a byte basis, and erasing ona region known as a “block”, NAND flash is organized on a block basis,analogous to a magnetic disk drive. As such, the terms sector, page, andblock may be used by analogy on a hierarchical basis. The size of eachof these data storage regions may vary depending on the actual productbeing discussed; however, the term block, when used in relation to thephysical memory denotes the smallest contiguous range of physical memorylocations that can be erased. Erasing a block sets all of the bits inthe block to “1”. Writing, sometimes called programming, sets selectedbits of a sector or a page of the block to “0” so as to result in thewriting of information (data) to the memory. Sector or page programmingoperations within a block are performed sequentially. Such programmingoperations can be performed only once for each sector of NAND memory,and an entire block of the memory containing the sector must be erasedprior to again writing the sector.

Since, modifying the data stored in NVS for a logical memory addresswould require another write to the physical memory location, whichcannot be performed immediately in flash systems, the usual approachtaken is to relocate the logical memory location in the physical memoryso as to write the modified data to an unused, but previously-erasedsector. The sector from which the data has been relocated now containsout-of-date data, and is no longer of interest to the user. As such itmay be considered a “dead or invalid” sector, while the data which iscurrent is considered to be stored in “live or valid” sectors. Sectorsthat are available for the writing of data may be called “free” sectors.The same terminology may be applied to describing pages, blocks, or thelike.

Metadata may include data about the data stored in the system. Themetadata may be, for example, the association of a logical data elementto a physical storage location. It may further include information onthe type of data, the time of writing of the data, error correctingcodes, and other information, depending on the requirements of a filemanagement system, thin provisioning system, distributed RAIDmanagement, disk emulation or other user needs.

When an interruption in system operation occurs due to, for example, apower failure, a hardware failure, or a software-related error, themetadata stored in volatile memory may be corrupted or lost, and thelocation of user data and other information, including housekeeping orstatus information, in the non-volatile storage (NVS) may no longer beknown as of the time of the interruption.

SUMMARY

A memory system and method for storing data in a non-volatile memory ofthe system is disclosed.

In an aspect, the method including maintaining a checkpointed copy of adynamic table in non-volatile storage (NVS), and maintaining atransaction log for the dynamic table in NVS. When the dynamic table isnot current or needs to be restored, the method includes discoveringchanges to the dynamic table that are not contained in the transactionlog and updating the dynamic table by applying the transactions in thetransaction log and the discovered changes. It may also includediscovering entries in the transaction log which did not actually occur,such as a situation where the transaction log is written to NVS beforeone or more of the transactions being logged has started and/or finishedbeing written to NVS.

In another aspect, the system for storage of data may include aprocessor, a volatile memory device (VS); and a non-volatile memorydevice (NVS). The processor may be configured to maintain a dynamictable in the VS of metadata representing data stored in the NVS; anincrementally checkpointed version of the dynamic table in NVS; and, alog in VS representing transactions affecting the metadata the log beingincrementally checkpointed to NVS. The metadata may be repaired bydiscovering data written to the NVS between the last incrementalcheckpoint of the log in the NVS and the time of recovery or repair.

In yet another aspect, a computer program product is disclosed, theproduct being storable on a computer readable medium and havinginstructions for configuring a processor and memory system to maintainmetadata representing data stored in a non-volatile storage device(NVS). A checkpointed version of the metadata on NVS and a transactionlog may be maintained in NVS, and the metadata may be repaired by:applying the transactions of the transaction log to the checkpointedmetadata to update the metadata; discovering data written during a timewhen the transaction log had not as yet been updated to include atransaction; and, applying the transactions in the ordered recovery logto the updated metadata.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates a data storage system having volatile andnon-volatile storage circuits;

FIG. 2 (A) is a flow chart showing the method a maintaining checkpointedmetadata in non-volatile storage (NMS); (B) is a detail of the methodshowing a method of determining when a segment of the metadata should becheckpointed; and, (C) is a continuation of the method shown in (B);

FIG. 3 (A) is a flow chart showing a method of recovering metadata (partI); and (B) is a flow chart showing the method of recovering metadata(part II);

FIG. 4 is an example of a data structure for an array A stored on aplurality of memory modules, which may be a logical or physicalarrangement of memory modules; and

FIG. 5 is an example showing the assignment of logical data elements tophysical modules of a memory system, where the physical arrangement ofmodules is in a binary tree with multiple roots;

FIG. 6 (A) is an example of the data structure of an index word of themetadata; and (B) is a portion of the index word for another arrangementof modules;

FIG. 7 shows an index word as being used to locate a specific basic dataunit in a memory array;

FIG. 8 shows the data structure of a quad data unit of memory (QDU);

FIG. 9 shows the spare area fields in the spare area;

FIG. 10 shows the hierarchy of metadata structures for a 2-chip memorycircuit;

FIG. 11 shows the data structure of a Root Block Record (RBR);

FIG. 12 shows the data structure of the RBR spare area;

FIG. 13 shows the data structure of the Index Block (IB) spare area;

FIG. 14 shows the data structure of the Map Table (MTE) spare area;

FIG. 15 shows the data structure of a Map Table Entry (MTE);

FIG. 16 shows the data structure of the MTE location field of FIG. 15;

FIG. 17 shows the data structure of the MTE location field in the sparearea;

FIG. 18 shows the data structure of the sequence number field of FIG.15;

FIG. 19 shows the data structure of a checkpoint block (CPB) spare area;

FIG. 20 shows the data structure of a log entry for a Map Table Entry(MTE);

FIG. 21 shows the data structure of the log entry for a checkpoint blockwrite operation;

FIG. 22 shows the data structure of the log entry for a block eraseoperation;

FIG. 23 shows the data structure for the log entry for a blockassignment operation;

FIG. 24 shows the data structure for the log entry for a bad block;

FIG. 25 shows the data structure for the log entry for padding the log;and

FIG. 26 shows the data structure for the log block spare area.

DETAILED DESCRIPTION

Exemplary embodiments may be better understood with reference to thedrawings, but these embodiments are not intended to be of a limitingnature. Like numbered elements in the same or different drawings performequivalent functions. Elements may be either numbered or designated byacronyms, or both, and the choice between the representation is mademerely for clarity, so that an element designated by a numeral, and thesame element designated by an acronym or alphanumeric indicator shouldnot be distinguished on that basis.

Reference may be made in this application to systems, apparatus,components, or techniques that are known, so as to enable a person ofordinary skill in the art to be able to comprehend the examplesdisclosed in the specification. The examples are intended to enable aperson of ordinary skill in the art to practice the inventive conceptsas claimed herein, using systems, apparatus, components, or techniquesthat may be known, disclosed herein, or hereafter developed, orcombinations thereof. Where a comparison of performance is made betweenthe examples disclosed herein and any known system, apparatus,component, or technique, such comparison is made solely to permit aperson of skill in the art to more conveniently understand the presentnovel system, apparatus, component, or technique, and it should beunderstood that, in complex systems, various configurations andconditions may exist where the comparisons made may be better, worse, orsubstantially the same, without implying that such results areinvariably obtained or constitute a limitation on the performance whichmay be obtained.

It will be appreciated that the methods described and the apparatusshown in the figures may be configured or embodied in machine-executableinstructions, e.g., software, or in hardware, or in a combination ofboth. The instructions can be used to cause a general-purpose computer,a microprocessor, a special-purpose processor, such as a memorycontroller, DSP or array processor, or the like, that is programmed withthe instructions to perform the operations described. Alternatively, theoperations might be performed by specific hardware components thatcontain hardwired logic or firmware instructions for performing theoperations described, or by any combination of programmed computercomponents and custom hardware components, which may include analogcircuits. Such hardware components may include field programmable gatearrays (FPGA), application specific integrated circuits (ASIC), mixedlogic and analog circuits, and the like.

The methods may be provided, at least in part, as a computer programproduct that may include instructions which may be stored or distributedon a machine-readable medium and which may be used to cause a computer(or other electronic devices) to perform the function or method. For thepurposes of this specification, the terms “machine-readable medium”shall be taken to include any medium that is capable of storing asequence of instructions or data for reading by, or for execution by, acomputing machine or special-purpose hardware and that cause the machineor special purpose hardware to perform any one of the methodologies orfunctions described herein. The term “machine-readable medium” shallaccordingly be taken include, but not be limited to, solid-statememories, optical and magnetic disks, magnetic memories, and opticalmemories.

For example, but not by way of limitation, a machine readable medium mayinclude read-only memory (ROM); dynamic random access memory (RAM) ofall types (e.g., S-RAM, D-RAM, P-RAM, M-RAM); programmable read onlymemory (PROM); electronically alterable read only memory (EPROM);magnetic random access memory; magnetic disk storage media; and, flashmemory of all types (e.g., SLC, MLC, phase change), other non-volatilememory types that are known or may be subsequently be developed, or thelike.

Furthermore, it is common in the art to speak of software, in one formor another (e.g., program, procedure, process, application, module,algorithm or logic), as taking an action or causing a result. Suchexpressions are merely a convenient way of saying that execution of thesoftware by a computer or equivalent device causes the processor of thecomputer or the equivalent device to perform an action or a produce aresult, a representation of which may be stored, for example, in amemory location, or be used to act on an external device or system,either locally or over a network.

When describing a particular example, the example may include aparticular feature, structure, or characteristic, but every example maynot necessarily include the particular feature, structure orcharacteristic. This should not be taken as a suggestion or implicationthat the features, structures or characteristics of two or more examplesshould not or could not be combined, except when such a combination isexplicitly excluded. When a particular feature, structure, orcharacteristic is described in connection with an example, a personskilled in the art may give effect to such feature, structure orcharacteristic in connection with other examples, whether or notexplicitly set forth herein.

Metadata may include data about the data stored in the system. Themetadata may be, for example, the association of a logical data elementto a physical storage location, and the association of a physicalstorage location with a logical data element. It may further includeinformation on the type of data, the time of writing of the data, errorcorrecting codes, and other information, including information on thestate of the physical storage location, and the like, depending on therequirements of the particular system. Changes to the metadata are madeto the metadata itself, and may be also made to a log so as to keep themetadata coherent with the stored data that the metadata is intended torepresent.

Metadata may relate to data stored in a die, a chip, a module, a volumeor a system, and may refer to, or be referred to by other metadata. Forsimplicity, the metadata associated with the storage of data on a die isdiscussed, and then aspects of the metadata stored on a chip, module orsystem are introduced to the extent needed. The metadata may beorganized as a table indexed on the “logical block address” (LBA), butmay also be stored with respect to the physical memory locations (e.g.,PBA as well. Often an address index is associated with individualsectors or pages on a disk, or sectors or pages of a block on a flashdie, and may be 512 bytes. In other aspects, the address index may beassociated with a page having a plurality of sectors (typically 4). Inthis context, the term LBA may refer to the smallest increment of dataaddresses being represented by the metadata; for example 512 bytes, or2K bytes. Where the stored data has attributes that are stored in thememory, such as in a spare area of a flash chip, the presence of suchdata may be included as one of the attributes of the LBA and beconsidered as local metadata.

Included in the metadata for an LBA may be the physical address of thelocation in which the data for the LBA is stored, and an LBA sequencenumber. The LBA sequence number may be particular to each LBA and may beinitialized at the reset of the associated memory device, or thesequence number may be set to a value by a command. Each time the dataof the LBA is altered, the value of the sequence number (SeqLba) of theLBA may be incremented by unity. If the sequence number is associatedwith more than one LBA, the sequence number may be set to the currentvalue of a counter rather than incremented. Alternatively, the sequencenumber may be a time stamp or portion of a clock value, a random number,or another otherwise arbitrarily assigned value

Where the term LBA, or the like, is used to refer to data received froma process initiated a host or user computer, the user may consider thatthe LBA may refer to either a logical or physical address in the memory.The memory system may accept this designation, and form a mappingbetween the user representation of the data location and the actual datalocation in the memory by considering that any user data location is alogical location in the memory. Thus, the file management system of auser may be substantially decoupled from the operation of the memorysystem, and a plurality of file management system types, which may belegacy software, may operate successfully on the host computer.

For simplicity of description, the memory locations of the memory systemherein may, from the user standpoint, be described as a contiguous spanof memory addresses, similar to that used to manage RAM-based memory,and the memory address space may be partitioned into sub-areas in theuser memory space, or may be configured by the memory system to allocatesuch areas to different user processes. The user program may treat theLBA address range as being randomly accessible, as in a RAM memorysystem, as a block orient device, or using any other addressing scheme.

Where a concept equivalent to RAID (Reliable Array of Inexpensive Disks)is used, a same sequence number may be assigned to corresponding dataelements in each memory circuit of the stripe where the RAID group dataare stored. Assigning the same sequence number value to each portion ofthe RAID stripe permits verification that the data read from eachportion of the stripe is the most recent data that was written to thatportion of the stripe, and that some portion of the stripe did notreturn data with the correct address but representing an older versionof the data. The sequence number need not be sequential but only needshave a property of being able used to verify that all portions of theRAID stripe belong together. Examples of such non-sequential “sequence”numbers could be a shared random number, the T1 Data Integrity Field(DIF), or a checksum of another portion of the stripe: e.g., chunk B'sSeqNum is a CRC of chunk A, chunk C's is a CRC of chunk B . . . E's isof D and A's is of E. The SeqNum's of the stripe portions could bepieces of a CRC or ECC computed over all or a portion of the stripe, orthe like.

Changes to the metadata may be recorded in a log and writtensequentially to the head of the log, which is achronologically-advancing record of the transactions associated withmaintenance of the metadata. The storage space allocated to the log isfinite, and thus free space may be reclaimed from, for example, the tailof the log to prevent the log file system from becoming full when thehead of the log wraps around when the log file is maintained in acircular buffer. However, the log data may be maintained as a linkedlist or other data structure. The log file itself may also be consideredas metadata.

The metadata for a chip or a module may be written to a chip or chips onthe module, so as to maintain the module as an autonomous entity. Thefailure of a chip may cause the loss of data unless there is a mechanismfor the recovery thereof. User data may be stored in a memory system bystriping the data across a plurality of modules in a RAID arrangement,and the data stored on a failed module may be reconstructed into a sparemodule using the RAID.

Where the metadata is stored on a module and a chip or memory area ofthe module, containing the stored metadata, fails, then the storedmetadata may be lost unless an error recovery mechanism is provided. Themetadata for chips of a module may be protected against loss by storingthe metadata in RAID stripes across a plurality of chips of the module.Since the redundant parity data would only be expected to be used whenan unrecoverable error occurred in a metadata block (including the log)stored in the module, the RAID may be of a high order. That is, in amodule having 18 chips, the metadata itself may be stored on 17 chips,and the parity data on the 18^(th) chip. The parity data is usually notread unless there is an error needing correction. As such, the storagearea needed, and the local processor load, are only slightly increased.

So as to associate the data written to the storage medium with a logentry, a different sequence number (PgmSeqNum, PSN) may be associatedwith each transaction affecting the data or metadata, or block status onthe NVS. The value of PgmSeqNum may be initialized at a time where themedium is initialized or reset, and may be incremented by unity for eachLBA data or other data written to the NVS, a block is erased, or otherrecordable action occurs with respect to the NVS. The value of thePgmSeqNum may be stored along with other data characterizing the LBAdata in, for example, spare areas of NVS associated with each sector orpage. A spare area of NVS may be any address range that is allocated tobe used for the storage of metadata or other information that is not thedata itself that is being stored. The spare area may be contiguous to asector, or a page, or may be one or more non-contiguous address ranges.When associated with a sector or page, the spare area is sometimescalled auxiliary data. Typically, we will use the terms interchangeablyherein.

The log file may contain an entry for each operation on the storagemedium that changes the data stored thereon or the location of the datastored, and may include, the LBA, the previous physical memory location,the new physical memory location, SeqLba, PgmSeqNum, and any otherinformation which may have been needed in order to update the metadatafor the LBA. The metadata and the log may also contain informationrepresenting the status of a block, including the pages and sectorsthereof. Such information may be, for example, that the block, pages orsectors are one of free, live, dead, or bad.

The log file may exist in NVS; however, a segment of the log filerepresenting the most recent transactions may be stored in volatilememory (such as DRAM) at the moment that a “crash” occurs. The segmentof the log file in volatile memory may not as yet have been written tothe NVS before the metadata becomes lost or corrupted by the crash.Where the transaction data is said to have been entered in the log file,the segments of transaction data already stored in the NVS is meant,unless specifically mentioned to the contrary. This discussion presumesthat there may be insufficient remaining power remaining a time of apower failure, or other circumstance, where the current metadata and thetransaction log have not been completely stored from the volatile memoryto the NVS. Where all of the metadata and the transaction log can bestored in NVS prior to cessation of operation, this may be termed a“clean” shutdown, and the metadata, at least as updated by anytransactions in the stored log, is a current representation of the datastored in the flash memory. In the case of a crash associated with aprogramming fault or similar event, there may be no opportunity toperform the data transfer, or the data transfer may be incomplete orcorrupted.

The metadata, the log file, and similar information may be stored in NVSin, for example, circular buffers. In an aspect, the metadata and logdata may be stored in data structures which are allocated dynamicallyand freed when no longer needed, forming a chain rather than a circle.Segments of the metadata, representing ranges of LBAs (which may not beeither complete or contiguous) may be periodically added (checkpointed)to the stored data in NVS by being placed at the head of a NVS metadatabuffer so that, eventually, all of the LBA metadata has been stored inthe NVS, although the stored metadata may represent a “snapshot” of eachof the LBA address ranges at a time in the past. The NVS memoryallocated for checkpointing is sufficiently large so that at least anentire current set of the metadata and any associated transaction logfor the relevant storage medium may be stored therein. Eventually, thebuffer may logically wrap around and old data may be overwritten.Generally, only the most recent metadata set is used to recover from acrash; however, older metadata may be retained for diagnostic purposes,where the storage area allocated for the metadata storage exceeds thatfor a complete checkpoint.

The size of the transaction log file in NVS needs to be at leastsufficient to record the changes made to the metadata subsequent to thestorage of updated metadata for each LBA address range (the lastincremental checkpoint), so that a complete set of metadata for thestored data is stored in NVS, or is recoverable from the NVS. Theperiodicity of metadata updates and the length of the log file in NVSare design trade-offs, and may be adjustable dynamically depending onthe mix of read and write operations.

To provide context for the examples, an available flash memory device isused to characterize the NVS. The use of a specific memory device is notintended to suggest that other NVS memory devices, which may includenon-volatile memory types being developed, or which may be developed,that have similar functional properties, are not equally usable,depending on the specific design considerations for the memory system. Acombination of several different NVS memory technologies may be used forthe NVS, and a combination of several different memory types may also beused for the volatile storage. Both the volatile memory circuits and thenon-volatile memory circuits may include some amount of the other memorytype for convenience.

An example NVS device in current production is a 1 GBtye flash memorycircuit, Samsung part number K9W8G08U1M, having two 512 MByte dies inthe same physical package. The device has a shared 8-bit I/O bus, and anumber of shared control signals. The two dies have separate enable andready/busy signals. For simplicity, when a flash memory device isreferred to in the examples, only one of the dies is meant, except whenoperation of the two dies in a module or chip is discussed. However, theextension to chips of larger or smaller capacities and to multiple chippackages would be understood by a person of skill in the art. It will beunderstood that the specific design of the flash memory chip used in theexample is so as to facilitate understanding of the example, and thatdiffering specification devices, which may have different busstructures, data capacities, and the like, may be equally usable. Thechoice of memory circuit may change as the NVS memory industry evolves.

Each die contains 4096 blocks; each block contains sixty four (64) 2KByte pages. That is, each die has a capacity of 512 Mbytes (MB) and apackage of two dies (which may be a chip) has a capacity of 1 GByte(GB). Each page may also be comprised of four (4) 512 byte sectors. Eachpage may include a 64 byte region used to hold local metadata, which maybe termed auxiliary data for the sector. The data and local metadata ofa page may also be differently arranged, with metadata for the entirepage contained in one 64 byte region or allocated to the sectors of thepage. In an example, data may be read by transferring an image of anentire page from the flash storage into a 2 KByte+64 byte volatile dataregister. The data thus read may be accessed from the volatile dataregister as byte data, or the entire page shifted out over a data bus. Asubset of the page may also be shifted out, since the read pointer canbe started at any byte in the page. Where reading of a page or a sectoris described, the local metadata may be presumed to have also been readshould the metadata have been needed. When needed, the metadata may thenbe accessed without transferring the remaining data of the sector orpage.

Reading a page from the non-volatile memory circuits into the dataregister may take about 25 microseconds, and the data may be shifted outto the chip data bus at a rate of 20 MBytes/second. Shifting an entirepage to or from the register and the bus requires about 100microseconds. Where only the auxiliary data is needed, the read time maybe reduced to the approximately the 25 microseconds needed to read thedata for a page into the data register.

Before a block can be used to store data, the must be erased, a processwhich may take about 2 milliseconds. Erasing sets all bits in the blockto “1”, and subsequent write (programming) operations selectively clearbits to “0”. Once a bit is “0”, it can only be set to “1” by erasing theentire block. That is, once one or more sectors of a block have beenwritten to, the same sectors cannot be written to again until the entireblock has been erased. Blocks that are only partially filled maycontinue to have data written thereto, to the free sectors or pages inascending order.

Writing may be carried out by shifting data into the chip data registerand then executing a command that writes the data into the non-volatilememory (NVS) circuit; writes take about 200 microseconds, exclusive ofthe time need to move the data from the bus into the data register. Thedata and metadata area of a page can each be written up to four timesbetween erasures, where the page is considered as comprised of four (4)sectors. That is, each of the sectors of the page may be separatelywritten in increasing sequence order. This aspect may permit the page tobe treated as four 512 byte sectors, and each sector may have anassociated ECC, or other local metadata. The pages in a flash memoryblock are written sequentially, from low page addresses to high pageaddresses. A memory address of stored data may be considered to berepresented by, for example, the block number, the sequential pagenumber in the block, and the sector number, and may include the locationof a byte within a sector, if needed. Once a page has been written,earlier pages in the block can no longer be written until after the nexterasure of the entire block.

Often, in the examples herein, a page is used to describe the smallestcontiguous group of memory locations being read, written, or the like.This is for simplicity in discussion. As has been previously described,many NVS circuits are writable at the sector level, where there may be aplurality of sectors (typically 4) in a page. As has been previouslydescribed, the sectors of a page may be written in sequence so that apage may be written as four sectors, in increasing order, but notnecessarily together. When data is read from a page, the data istransferred to a volatile data register, and only a portion of the datafurther transferred or operated upon. For example, only a sector of apage, only a byte of data, or only the spare area of the sector or pagemay be actually placed on the bus of the chip.

The use of the terms sector, page, and block in the previous discussionreflects the commonly accepted terminology for flash memory circuits,and resulted from the adoption of several terms from the rotating diskmemory technology. However, where data structures are described herein,the term “block” may have a different meaning, which is made clear inthe subsequent discussion. A block of data in a data structure has asize and characteristics defined by the logical data structuredefinition, and may not correspond to a block of flash memoryrepresenting the minimum amount of memory that can be erased in an eraseoperation. The term data “segment” may refer to a block of data of afixed or variable size that may not correspond in size to a flash memoryblock of physical memory. The terms page and sector may also be replacedby other terminology that is used when referring to data and thelocation thereof. This should be clear from the context of the examples.

In an example of a system 1, shown in FIG. 1, a computer or businterface processor 10 communicates with a volatile storage device 20and a non-volatile storage (NVS) device 30, which may be a flash memory.The volatile storage 20 may be a device such as a dynamic random accessmemory (DRAM) a static random access memory (SRAM), or the like.Volatile memories, or volatile storage (VS) are known to requireessentially continuous application of a source of electrical power inorder to maintain the integrity of data stored in such memory. Oftenthis power is supplemented by a battery backup system which may be atany level of the system architecture; however, such a backup powersupply does not persist indefinitely and, for purposes of this example,a loss of system prime power or other power interruption is consideredto result in a loss or possible corruption of the data in the volatilestorage 20. For convenience, the volatile storage (VS) is describedherein as RAM. Non-volatile storage (NVS) may be a device having memorycircuits or media where the data integrity is maintained even after aloss of power. Such media as magnetic disks, or flash memory of varioustypes, are currently used. For purposes of the examples, a SLC NANDflash memory circuit is used as the NVS building block, withoutintending to limit the type of NVS that may be used.

The bus interface 10 may communicate with other components of acomputing system such as a host processor, which may have associatedtherewith other storage media, such as RAM, magnetic disks, magnetictape, and the like, and may also interface with external communicationsnetworks. The bus interface 10 may be configured to interface with a busof a larger NVS memory system, of which the assembly of FIG. 1 may beconsidered to be a module. Such a memory system is shown in FIG. 2. Inan aspect, the assembly of FIG. 1 may be considered as a solid statedisk (SSD), and may be used individually or as part of a larger memorysystem.

The RAM 20 may be used to store data being operated on by computerprograms which may also stored in the RAM prior to execution; the RAMmay include an area for the volatile storage of data and metadata, themetadata being used to represent aspects of the data, programs, furthermetadata, log files, and the like, that may be stored on the NVS.

Where the module is part of a larger memory system, other volatilememory areas may also be provided for the temporary storage of programinstructions and data for operation on by another computer, processor,or the like. The RAM associated with a memory module may be used as anintermediary storage between the NVS devices and any other storagemedium.

To reiterate, the term module is a convenience for visualizing a groupof NVS memory circuits, which may be associated with a computing system.The module may also include a bus interface for communicating with otherportions of a system. A module need not have all components physicallyresident on a single circuit board, substrate, or package.Alternatively, more than one module may be resident on a single board,substrate or package.

The metadata being manipulated may stored in RAM as well as in the NVSas, at the present time, the access time for reading and writing data inNVS is longer than for data in RAM, and the NVS may also havelimitations such as the number of writes or erases before wear out. Onemay consider the metadata in the RAM (VS) to be the volatile metadata,and the metadata in the NVS (e.g., flash) to desirably be a non-volatilealmost current or current image of the volatile metadata. Thus, whenmetadata is used to manage the storage and retrieval of data on NVS, thespeed of operation may be faster when the metadata modified is in RAM.Where the term data is used herein, any of user data, metadata, filedata, program instructions, log files and the like, is meant, exceptwhen specifically excluded.

The metadata in the volatile storage (VS) may be lost, corrupted, orotherwise rendered unusable by a loss of system power, or otherunexpected events. This is often called a “crash”. Herein, the term“crash” is used to represent any event that causes the metadata in VS tobe rendered unusable for its intended purpose. The cause of a crash maybe a power failure, a hardware defect, a software programming error, orsimilar occurrence. This occurrence may also known as a “dirty”shutdown, so as to differentiate the situation where the system is shutdown in an orderly manner (a “clean” shutdown”), and where all of thedata and metadata is correctly stored (checkpointed) in NVS, and thestored metadata, or a combination of the stored metadata and a storedtransaction log represents the current state of the stored data.

In this example, volatile metadata is stored in RAM, the metadatadescribing the location and attributes of each logical element of datastored in the NVS. The logical data element storage description may havethe granularity of, for example, a sector, a page, a block, or a volume.In this example, the logical element is a sector. When the system 1begins operation, data received by the system 1, or produced byoperation of the system and its associated software programs, may bestored or retrieved from the NVS. When data is written into the NVS, thedata is organized as sectors, each having a logical block address (LBA).The metadata associates the logical block address (LBA) with thephysical memory location of the sector in the NVS, and may also containother information regarding the data, such as a time stamp, sequencenumbers (e.g., SeqLba, PgmSeqNum), data type, checksum or other errorcorrecting codes (ECC), and the like. The time stamp may relate to asystem timer so that the relative order of operations may be organizedwith respect to the arrow of time to a predetermined granularity.

A snapshot (checkpoint) of the volatile metadata may be taken, stored inNVS and used as a first baseline. Each time that the file managementsystem causes data to be written to the NVS, the association between thelogical element and the physical location thereof is updated and storedin the volatile metadata, along with any changed attributes of the dataor storage location, and the transaction is also stored in the log involatile storage.

Periodically, or after a predetermined number of updates to the volatilemetadata, segments of the metadata (for example, pages) are written intoNVS so that, after a period of time or number of operations, themetadata stored in NVS constitutes a new baseline, as all of themetadata pages have been written to NVS. The metadata may be stored in acircular buffer having a depth greater than the number of metadata pagesso that a complete metadata set, albeit perhaps having differentvalidity times, is in NVS. However, as soon as an operation is performedwhich modifies the metadata page in volatile memory such that it differsfrom its checkpointed image in NVS, the stored data is out-of-date, anddoes not represent the current status of the entire memory system. A logof the transactions resulting in changes to the metadata is maintainedin volatile storage, and segments of the log data are incrementallywritten from the volatile memory into NVS, typically after apredetermined elapsed time or number of metadata changes. This wouldenable the stored log to be used to update the stored metadata to a timewhere the last segment of the log had been stored in NVS.

The current volatile metadata or the volatile log data may not have beenwritten (checkpointed) into NVS immediately, and the occurrence of acrash may render the metadata and log data in RAM unusable; and, themetadata image in the NVS, and the log in the NVS, may not be completelycurrent. Data may have subsequently been written to the NVS, garbagecollection or wear leveling housekeeping operations may have resulted inrelocation of data, or the like, and the record of the location of somethe data may now be lost. As well, data may have been transferred fromone physical location in the NVS to another for other reasons and theaction not as yet persistently recorded. These “lost” data need to belocated, or “discovered”, and the metadata updated so that the systemmay resume operation on a metadata set that has coherence with the dataset as existed in reality at the moment of the crash.

The metadata may include other information such as a table of badblocks, usage data, such as the number of previous erase operationsperformed, for each flash block, the occupancy of each flash memoryblock, and the like. As sectors of a memory block are written, thephysical page address (index) of the block to be written to isincremented, and each block ‘i’ may characterized by an occupancy, whichmay be represented by a value MaxNum[i], which is the index number ofthe highest address sector in the block to which data has been written.Sectors having higher page numbers are expected to be all “1”, as theyhave been previously erased as a result of a block erase operation, andhave not as yet again been written to, or “programmed.” MaxNum=0 may beused to indicate that the block has been previously erased, and thatdata has not as yet been written to the block. A MaxNum[i]=MAX_BLOCK,where the value MAX_BLOCK is the number of sectors in the block, wouldindicate, for example, that the block has been filled. (In this example,the block comprises 64 pages having 4 sectors per page, so thatMAX-BLOCK=255)

The process of recovery from a crash may include scanning thecheckpointed metadata stored in NVS so as to determine the most currentversion of each metadata segment. Where more than one image of ametadata segment (for example, a logical address range) of the metadatais found, then the older of the two segments is ignored. The oldest timeof each retained most-current metadata segment sets a time boundary forthe consideration of changes to be made on the basis of the transactionlog retrieved from the NVS. Data in the transaction log that has beenstored in NVS, and which is older than the oldest time for a retainedsegment represents changes that were already recorded in the storedmetadata. So, the update may start where the transaction log time equalsthe oldest most recent checkpoint time for each type of metadata.

In an aspect, situations may arise where a block has been erased, andthe occurrence thereof has not as yet been recorded in the transactionlog in NVS. Should the block be needed for a write operation, the eraseoperation may have been written to the transaction log in VS prior tomarking the block as having been erased in the metadata and writing newdata into the block.

Consider the metadata for a chip in this example. One of the attributesof such metadata data is that the metadata may describe the data writtento the flash memory device, as well as characteristics of the flashdevice itself. In particular, since the data in a block of a flashdevice is written sequentially, the information representing the highestpage and sector number MAX for each block “i”, MaxNum [i]=MAX, that hasvalid data may be stored as part of the metadata. Since the flash blockwas erased at some time prior to the time when writing first began tothe block, one expects that the sectors and pages higher than the valueof MaxNum [i]=MAX will be all “1”s.

As part of the recovery from a crash, the last valid stored metadata setis read from the NVS to the VS. The transaction log data stored in NVSis also read from the NVS into VS, at least from the sequence number ortime representing the oldest last stored metadata segment of thecheckpoint, and the log processed so as to update the metadata to thelast time that the log was saved to the NVS. Actions by such as writingdata, including null data, and by other NVS management systems, such asgarbage collection or wear leveling, taken subsequent to the last savingof the log to NVS, need to be discovered by other means.

The metadata regarding the value of MaxNum[i] for each block “i” may bescanned. Using the value of MaxNum[i], for each block “i”, the sectorcorresponding to MaxNum[i]+1 of the block is read and, if all the bitsof the data area are “1”, with appropriate metadata (such as checksum,SeqLba), one may thus determine that no additional data has been writtento the block since the metadata for the block was stored in NVS as partof the rolling checkpoint or snapshot, or the saving of the volatiletransaction log to the log in NVS.

Data stored in sectors less than or equal to the value of MaxNum[i]=MAXmay have been logically deleted, or moved to other areas of NVS. If thedata has been moved, and the transaction had not been stored in the login NVS, the data will now be discovered by the process of checking fordata written into sectors above the value of MaxNum[i] for each of theblocks in NVS. The data discovered in sectors above the value ofMaxNum[i] may have, as part of the associated sector or page metadata,values for a sequence number (PgmSeqNum), and the current LBA sequencenumber (SeqLba), and the physical previous location of LBA. This datamay be written to a recovery log in volatile storage for the purposes ofupdating the metadata in VS so as to recover the metadata.Alternatively, the reading of the sector may be limited to the auxiliarydata, or spare data as, if this data is all “1”, then the data area ofthe sector may also be presumed to be all “1”. Reading the spare dataonly is a faster operation.

Inspection of the sector MaxNum[i]=MAX+1 may be sufficient to determinethat no additional data has been written to a block which has not beenerased, as the writing of data to sectors of a block proceedsincrementally in a positive direction. Once new data has been discoveredin a memory block, additional sectors are read, the sectors havingincrementally greater sector numbers, and the appropriate informationread from the descriptive data (local metadata) in the spare area so asto produce an entry in a recovery log, until the first sector that hasnot been written is discovered. At this juncture, all of the sectorsthat had been written to the block but not as yet been committed to thelog in NVS have been discovered, and added to the recovery log involatile storage.

The sector corresponding to the value of MaxNum[i]=MAX is alsoinspected. Two typical situations obtain. In the first, the data insector whose value is MaxNum[i]=MAX is the data that was written to thesector at a time previous to the crash and already represented in themetadata (at least as updated by the log that had been stored in NVS),and this data had not been “lost” and thus need not be recovered. In thesecond, the block had been erased, but the transaction had not as yetbeen written to the log. That is, the information in all sectors whosevalue less than or equal to MaxNum[i]=MAX has been either moved ordeleted, and the block has been erased. This action may have beenaccounted for by writing an erase transaction for the block to the log.If the data had been rewritten to another sector, the data will havebeen discovered by the process described herein, and the sector locationmay be associated with the LBA.

However, new data may have been written to the block after the eraseoperation and exactly MaxNum[i]=MAX sectors of the block written withnew data. The status area of the sector MaxNum[i]=MAX should beinspected to determine that, if valid data is present, that the data waswritten at a time prior to that where the last log segment had beencommitted to NVS. If later-written data is found, then all of the dataat lower sector numbers of the block is also newly-written data whichhas been found. However, if the data in the sector MaxNum[i]=MAX isolder than the time where the log segment had been committed to NVS,then all of the data in the lower sector numbers has already beenaccounted for either in the stored metadata or the stored log.

In another aspect, the block may have been erased but as yet not writtento for MaxNum[i]=MAX times, so the sector that is being checked had beenerased. In such a circumstance the first sector of the block should beread to see if anything was written to the block. If the transactionpolicy is for the log segments is to sometimes be written to NVS beforethe data itself is written to NVS, then the fact that less pages havebeen written than the metadata shows have been written does notnecessarily mean the block was erased.

It is also possible to prevent certain cases special cases fromoccurring depending on the policy used to write the log: for example ablock may not be permitted to be erased until an entry indicating thatthe block is scheduled to be erased is written to NVS, or no writeoperations may be permitted in a newly erased block until the log entryindicating that the block had been erased has been written to NVS. Thus,cases where the block has been erased and written to, but the metadatadoes not reflect the erase operation, would not occur.

Various special cases may be avoided by constraining other properties ofthe system. For example, a newly erased block may not be allowed to bewritten to for a period of time larger than a log entry is permitted toremain in VS without being written to NVS, or may not be not written tountil enough writes have occurred that the log entry containing anindication of the block erasure will have been flushed to NVS due to thegrowth of the log. In the case where data may be written to NVS beforethe data corresponding to the log entries was written to NVS, a numberof methods could be used to prevent having to “undo” log entries whoseoperation did not actually start and/or complete. One method would be todiscard as many log entries from the tail of the log as could have beenwritten in advance of the actual writes occurring. Or, entries could beverified starting from the tail of the log to determine which writes hadcompleted

The local metadata for each sector ‘j’ of block “i” contains a sequencenumber (PgmSeqNum[i,j]; PSN), so that the sequential order of thewriting of each of the sectors may be determined over a plurality ofblocks. The discovered data in sectors of each of the blocks of the chiprepresents data that has been written to the sectors during a timebetween the last storage of a transaction log segment to NVS and thecrash.

The recovery log of discovered sectors in the plurality of blocksrepresented by the metadata may be ordered or processed, using PgmSeqNum[i,j], for example, from oldest at the tail to newest at the head. Usingthe LBA in the metadata stored in the sector or page spare data area,the recovery log provides information on the current association of thesector or page memory location with the LBA, and the immediatelyprevious memory location of the LBA. As such, when the recovery log isprocessed from the tail to the head, the LBA associated with each sectoror page is updated by deleting the association of the LBA with aprevious lost sector or page, and associating of the LBA with the sectoror page in which it was discovered during the recovery operation. Thisaction also identifies “dead” memory locations so that the entire blockmay eventually be recovered by erasing the block, once all of the pagesare either dead or free, or in accordance with some other policy. Therecovery log data for block erasures may not include a sequence number,but the information may be used to update the free block table and toset the MaxNum[i] for erased blocks to zero.

After the completion of the updating, each of the LBAs has beenassociated with the sector, page and block in which the valid dataphysically resides. The status of the pages in each of the physicalmemory blocks is also updated so that housekeeping operations such asgarbage collection and wear leveling can be performed.

This example has been simplified by, for example, ignoring maintenanceor housekeeping operations such as garbage collection, wear leveling,bad-block detection and handling, and the like. Many of these operationsare manifest as movement of data to new sectors, erasing of blocks,changing the bad block table, and the like, and are accounted for in thereconstruction of a valid metadata set by the process described.

An example of the method of recovering the metadata for the data storedin NVS after shutdown or crash is shown in FIGS. 2 and 3. A method 500of maintaining the metadata characterizing the status of the flashmemory, and the data stored therein is shown in FIG. 2A. A write request(step 510) is received. This request may be for any operation thatcauses the modification of information or data stored in the NVS. Thepresent PgmSeqNum is incremented by one (step 520) and transactioninformation related to the write request is entered at the head of thetransaction log in VS (step 530). The transaction may be performed by,for example, writing a page of data to a particular page location in ablock of flash memory (step 540). The metadata in VS is then updated toreflect the transaction (step 550). This metadata may be comprised, inpart, of a plurality of logical data addresses, such that each of thelogical data addresses is mapped to a physical memory address of theNVS. For checkpointing purposes, the metadata may be allocated to aplurality of segments, each segment containing a plurality of logicaldata addresses, for purposes of managing the storage of the metadata inthe NVS. When the log or the metadata has been updated, a status ischecked to determine whether the metadata segment that has been updated,or a segment of the log, should be written to NVS (step 560). If noinformation needs to be saved to NVS, then the process returns to step510 and waits for a new write request.

If information needs to be saved to NVS, then the metadata segment orlog is written to NVS (step 580) and pointers to the most recent storedmetadata and log are updated. The process returns to step 510. Inanother aspect, an event, such as a command to perform a clean shutdownmay be received (step 570). This may be termed an event trigger and isprocessed in step 560.

The details of step 560 are shown in FIG. 2B. The present value ofPgmSeqNum is read (step 561) as well as the current system time (step562). The system time may be read from a counter that counts the numberof roll-overs of a 1-second counter, or any other time reference that ismaintained with respect to the flash memory circuit. The event bit ischecked (563) and the process exits to process 600 if the event bit isset. Otherwise, the value of PgmSeqNum and the system time are checkedagainst previously recorded values for the metadata segment or the log(step 564). Here, the difference between the current and a value of the“last” PgmSeqNum or “last” system time is determined. If the value isgreater than a limit, which may be a separate parameter for each of themetadata segments and the log, then the process exits to the mainprocess 500 with a Yes result so that the metadata segment, or the log,as appropriate, is written to NVS. The “last” value of the PgmSeqNum andsystem time, represents the last time that the particular metadatasegment or the log has been written (checkpointed) to NVS. The log issaved from the “last” PgmSeqNum to the present. The “last” PgmSeqNum andthe “last” time are then updated to the current values. If the result ofstep 564 is No, then the process exits to the main process with a Noresult.

In the circumstance that the process 560 exits to process 600 as aresult of the event bit being set, the steps of the process 600 areperformed, as shown in FIG. 2C. The existing metadata segments in the VSare all written to the NVS as the current checkpoint of the metadata(step 610) and the log in VS updated to reflect these transactions.Then, the portion of the log in VS that has not as yet been written toNVS is checkpointed (written) to NVS (step 620), and the completion of a“clean” shutdown is reported (step 630). When the shutdown is performedin this manner, the stored log may be processed at startup so as toupdate the metadata to the time of shutdown.

Alternatively, the stored log and the volatile log may be used to updatethe metadata prior to shutdown, so as to minimize the time to re-start.As such, one will appreciate that the steps described may be performedin various orders, and some steps may be omitted or added, depending onother aspects of the design, and this specific example is provided so asto facilitate understanding of the overall concept.

When the shutdown is a “dirty” shutdown, the metadata and the log storedin the NVS may not represent the current state of the other informationstored in the NVS, and the metadata needs to be updated prior to use.

A recovery request is received (step 710) so as to initiate the recoveryprocess, as shown in FIG. 3A. The checkpointed metadata segments areread from the NVS to the VS (step 720). The log data is read, from theNVS to the VS for the period starting with the earliest “last” PgmSeqNumassociated with the checkpointed metadata to latest log information, andmoved to VS (step 730). The checkpointed here would be the last completeset of the segments of the metadata that have been stored to NVS,although they may have been stored segment-by-segment over a period oftime.). The log now in VS may be processed from the oldest entry to thelatest entry (step 740) so as to enter all of the transactions in themetadata (step 750). At this juncture, the metadata in VS has beenupdated to a time when the log was last checkpointed to NVS.

In an aspect, the individual transactions may not be written to the login a strictly time-order fashion, providing the PgmSeqNum associatedwith the actual time of performing the transaction is correct. Whenusing the log stored in NVS to update the stored metadata prior todiscovering “lost” data, the last PgmSeqNum of the log stored in NVS isconsidered to be the last valid PgmSeqNum, and log data associated withPgmSeqNum grater that that of the last valid PgmSeqNum is not used inthe metadata recover. Rather, the data associated with the higherPgmSeqNum is considered to be lost and may be discovered by thediscovery process. The stored log is ordered by PgmSeqNum prior to beingused to update the stored metadata.

The next steps of the method are intended to find or “discover” anysectors, pages or blocks of the flash memory that were written to, orerased, between the last checkpoint of the log and the crash. The systemprocesses will have moved all “live” pages and written them to freepages in another block prior to a block erasure. Therefore, “live” pagesthat were in an erased block may be presumed to have been moved, andwill be recovered, even if the move had not been recorded in themetadata and log in NVS. During the recovery operation, which may be theprocess 800, the metadata that had been stored in NVS, and which may notbe up to date, has been updated by the process 700, and has, for eachblock, a variable “MaxPage” whose value points to the highest pagenumber in the flash memory block where a live page is believed to bestored. Since the pages in a physical block of flash memory are writtenin sequential ascending order, all blocks above MaxPage in a block arepresumed to still be in the erased state of all “1”. This includes thepage local metadata. Any page above MaxPage in a block having datawritten therein, must therefore have been written after the last timethe metadata was checkpointed (as updated by the stored log, as in theprocess 700) and is considered therefore to be “discovered” data. Themetadata for the discovered page is written to a recovery log. Exceptfor corner cases, some of which are described elsewhere herein, the pageMaxPage is expected to contain data and local metadata related thereto,as would be true for all pages less than MaxPage, unless all of thepages below MaxPage had previously been moved by writing the contents toother blocks and the flash memory block had been erased.

The actual contents of the flash block are verified in process 800. Theupdated metadata, from process 700, are read for each flash block in thedevice (step 810). In particular, the MaxPage value, MAX, for the flashblock is read. At least one of the data or the metadata for the pageMaxPage=MAX is read (step 820). If the data is all “1”, then the pagehad been erased. There is the possibility that new data, to bediscovered, has been written to pages below MAX. As such a Yes decisionat step 830 results in branching to step 840 where the page number isset to “0”, since any new data written to the flash block will start atthe lowest block number and proceed in page increments in an upwarddirection. So, page “0” is read, and the information read is evaluatedto determine if new data has been written to the flash block. If theresult is that all of the data bits are “1”, this is the erased state,and thus one may conclude that no new pages can be discovered in thisflash block, and at step 860, with a Yes result, the process 800concludes for the particular flash block.

If data is discovered in the page “0”, then the local metadata for thepage is reported as having been discovered and the local metadata forthe page is stored in the recovery log (step 870). The page number isincremented by one (step 880) and the data read from the next highestpage. Step 860 is again performed and, depending on the result, thescanning continues incrementally higher in the flash block as new datais being discovered, or until a page which has not as yet been writtento (programmed) is found, at which point all of the new data to bediscovered in the flash block has been accounted for.

However, if the result of step 830 is No, then all of the pages belowMAX had previously been written, and the transactions had been accountedfor in the metadata, as updated by the process 700. The page number isincremented (step 850) so that the next highest page above MAX isevaluated (step 860). If the data is all “1”, then no data has beenwritten to this page or any higher numbered page in the flash block, andthere is no new data to be discovered. The process 800, for this flashblock, exits. Where the data was not all “1”, then new data has beenwritten to this memory block since the updated metadata was valid, andthis new data is thus discovered. The discovery is reported and recordedin the recovery log (step 870) and the page number again incremented(step 880) to determine if any further pages have been written to theflash block, until such time as all the pages of the memory block havebeen scanned, or step 860 determines that the block has not beenprogrammed. The scanning of the flash block has then been completed. Theprocess 800 is performed for each flash block. All pages above thehighest page having discovered data in a block are free pages, as theyhave not been programmed.

Many flash blocks will only require the boundary scanning, as theindividual pages of a flash block need be scanned only if the boundaryscanning indicates that there is data to be discovered in the block.That is, the method performs a scan of memory blocks so as to determineif a write or an erase may have been performed after the updatedcheckpointed metadata was valid, and scans only the pages of such ablock needed to recover changes to the metadata after the time that theupdated metadata was valid. In a case where MaxPage=MAX_BLOCK, then thelargest page number in the block is the only one that needs be evaluatedif there has been no change to the block.

This method has been described with reference to particular stepsperformed in a particular order; however, as with the other examplesdescribed herein, it will be understood that the steps, functions, oractions may be combined, sub-divided, or reordered to from an equivalentmethod. Accordingly, unless specifically indicated herein, the order andgrouping of such steps, functions, or actions, is not intended to beinterpreted as a limitation.

The individual chips may be combined into a memory array or system oflarger size and may be mounted to a circuit board so as to form amodule. Similarly, a plurality of modules may be mounted to a motherboard, substrate, or the like, so as to form a still larger memorysystem. The data integrity in a memory system may be further enhanced byone or more redundancy techniques, such as error correcting codes orRAID.

While the recovery of the metadata to a current state has been describedat the level of a memory system where a plurality of blocks isconsidered, the method may be used at higher levels of a system, wherethe lower level metadata may be considered as data, and such issues asfailed modules may be considered as the equivalent of bad blocks.

Where the data processing in this example is shown as being performed bya computer, the computer may be a memory controller or memory managementcircuit located on a circuit board that is a substrate or modulecontaining the memory, or be connected to such a module by a bus, sothat the data may be processed in another component of a larger system.The bus used for communication with other aspects of the system may beany of the varieties of bus architecture, industry specification, orproprietary format now known, or which may be developed, that iscompatible with the product with which the memory system may be designedto interface. Such busses may, for example, emulate the interfacecharacteristics of rotating magnetic disk storage systems, or beextensions or improvements thereon, such as extensions to support RAIDlike operation of modules located on said busses, such extensions mayinclude additional information used for synchronization of data amongstRAID groups or, for example, time synchronizing the operation of themodules.

In an aspect, instead of searching all blocks to find writes to the NVSthat had not as yet been written to the log, a smaller number of blockscould be searched if the policy for selecting where to write new datacan be followed in whole or in part, from the reconstructed state of thesystem.

For example, if the policy is to write into the block with the most freespace and after processing the log there are 3 blocks with N free pagesand 5 with N−1 free pages, then only those 3 blocks with N free pageswould have to be checked. If there were pages written to all three ofthose blocks, then they would now have N−1 free pages, so now the 8blocks with N−1 free pages would have to be checked. If new pages wereonly found in 7 of the blocks there would be no need to check any of theblocks with N−2 free pages as they would not be written to before theremaining block with N−1 pages.

To find any block which might have been erased, but not have beenlogged, it may be sufficient to check only those blocks with no ‘live’pages, where the policy is that blocks are not marked for an eraseoperation when they still have live data.

In an aspect, the data may be striped across a number of memory modules,or across a plurality of memory circuits or chips of a module, so as toimplement a RAID redundancy configuration, or a hierarchy of suchconfigurations, which may be differing versions of RAID. Suchconfigurations are compatible with the approach of the first example, asis illustrated in a second example.

In another example, the memory system may be organized as an array ofmodules connected by a bus system. A bus-connected array of memorymodules has been described in U.S. Ser. No. 11/405,083, InterconnectionSystem, filed on Apr. 17, 2006, which is commonly owned and which isincorporated herein by reference. A module of the bus-connected arraymay have the volatile storage 20 and the non-volatile storage 30 of thefirst example herein, and may have a bus interface or local memorycontroller 10. Recovery from a crash may be performed for each of thememory modules individually as described above. Bus-connected memorysystems may have additional protection against data loss by the use ofRAID techniques, as described in U.S. Ser. No. 12/079,737, MemoryManagement System and Method, filed on Mar. 26, 2008, which is commonlyowned, and is incorporated herein by reference.

FIG. 4 shows the logical organization of data which may be stored ondifferent memory modules so as to realize a RAID 5 organization with 4data modules and 1 parity module. Each LBA may be divided into a groupof four smaller LBA ranges (for example, sectors) and stored ondifferent memory modules. A parity value for each group of LBA rangesmay be computed and stored on a fifth memory module. Such anorganization of the data storage permits the recovery of data when amemory module fails or is otherwise unavailable when a data read is tobe performed. As described in application Ser. No. 12/079,364, thememory system of FIG. 4 may be operated so as to return valid data usingthe data from only 4 of the 5 modules. As such, the operation of thesystem may continue while the RAID data structure is being rebuiltafter, for example, replacement of a failed module.

In an aspect, data A is stored as four sequential areas of data A1, A2,A3 and A4 on separate memory modules, and the parity Ap is stored on afifth memory module. At each memory module the LBAs associated with thesequential areas of data may be the same, and as the SeqLba value forthe LBA in each module may have been previously initialized to zero at areset or initialization, all of the modules in the stripe for theparticular data area A will have received the same number of sub-blocksof data (which may be sectors) since that time. The sequence numbervalue SeqLba may be stored as part of the metadata in each module. Assuch, when the data for A is read from the memory modules andreassembled, each of the subsets of data A1, A2, A3, A4 and Ap may thusbe expected to have the same value of SeqLba.

RAID may be used to recover data where a module, or a portion thereof,has failed. Since the local metadata for each of the individual moduleswill have been recovered if there had been a crash, as previouslydescribed, the local metadata of the recovered LBAs will still have thecorrect sequence numbers SeqLba. The data from remaining 4 of the 5modules may be used to recover the data of a failed module, by readingthe data from the 4 valid modules and computing the XOR of the data. Theresultant data is the data that has been lost from the remaining module.So, after a failed module has been replaced, the data may be fullyrecovered and restored. In an aspect, the data may continue to beaccessed during the reconstruction of the data of the failed module to aspare module, or during the repair of the hardware, which may be byreplacement of the failed module, and may be performed on a hot-swappingbasis. A PgmSeqNum or other index for the data may be present in each ofthe separate metadata sets for each module corresponding to the storedA1, A2, A3, A4 and Ap (one of which is lost due to the module failure),and therefore the SeqLba for the recovered data may also be known. ThePgmSeqNum for the recovered data set may be re-initialized when it isrestored to the NVS.

When the contents of a failed memory module are reconstructed usingRAID, the reconstructed data may be stored in a replacement or sparemodule, and metadata associated with the storage of the data on themodule may be created contemporaneously

The locations of the memory modules within a memory system may bephysically different from the logical arrangement shown in FIG. 4.However the arrangement of FIG. 4 may also represent a physical memorysystem where a plurality of memory modules are organized in a linear busand connected to one or more memory controllers.

In another example, a tree-type memory system is shown in FIG. 5, wherethe memory modules associated with a stripe of a RAID 5 arrangementcorresponding to the logical arrangement of FIG. 4 is shown. Thecorresponding physical modules are D1, D2, D3, D4 and Dp. The assignmentof the data sub-arrays A1, A2, A3, A4 and Ap to physical memory modulesD1, D2, D3, D4 and Dp may be made using a computational algorithm, lookup table, or any other suitable technique.

In yet another example, a detailed design of data structures compatiblewith performing data recovery operations is described. In an aspect, theexample is directed to storage of data in a logical-block-addressableformat. Other data storage formats which may be used include file systemstorage, object data stores, NV computer main memory; some types ofstorage formats may be layered on top of a block based storage system,while still others could integrate aspects of the present application owithin an overall data management structure.

This detailed design is one of many possible designs and includesdetails which are provided to place the data structure design in thecontext of a memory system. As such, not all of the features andoperations described herein may be needed in any particular design, andfeatures may be added or deleted in accordance with the needs of thedeveloper. Further, while this description is somewhat more detailedthan the other examples, a person of skill in the art will realize thatthere remain a wide variety of housekeeping and other operations whichmay be performed, and which are not described in detail. Additionally,some portions of the data structure are not described, or are shown butare not described in detail. These portions may provide a reserved spacefor further development, or for the implementation of features which arenot the subject of this application, or are described elsewhere herein.Omission of any feature in the example is not to be taken as precludingthe addition thereof in a specific design, depending on other factors,such as economics, optimization of specific performance characteristics,or the like.

While the data may be protected against loss due to a hardware failureat the module level, or a higher level in the system by a RAIDtechnique, EEC (error correcting code) or the like, in this example, theoperations associated therewith are not described, and such operationsare considered to be subsumed in the read and write operations that arecommanded for execution.

For the purposes of this example, the hardware of a module may includethe functional areas shown in FIG. 1, where the non-volatile storage(NVS) 30 is a flash memory, which may be a multi-chip device, thevolatile memory (VS) 20 is DRAM, and the computer 10 is amicroprocessor, field-programmable-gate-array (FPGA), state machine, orthe like, which itself may include local memory; the local memory mayinclude volatile (VS) and non-volatile memory (NVS), including memoryfor local storage of program data. Alternatively, such program data maybe loaded from another memory or computer readable storage device. Thecomputer 10 may also include the circuitry for interfacing with anexternal bus, or have forms of interface to the remainder of the system.The hardware may be located on a single circuit board or substrate, or aplurality of the same.

In this example, and not by way of any limitation, a module may includefrom 8 to 16 flash circuits, each flash circuit (package) having 8 flashchips. A flash circuit (NVS) may have a capacity of 1 GB, so that 8flash circuits would have a capacity of 8 GB and 16 flash circuits wouldhave a capacity of 128 GB. The flash memory chip may be characterized ashaving a programming time (write time) of 200 usec typical and 700 usecmaximum, a page read time of about 100 us, and an erase time of 1.5 msectypical and 2 msec maximum. The circuits are organized to communicatewith the computer 10 over local busses having a capacity of 20 MB/s fora total module capacity of 160 MB/s. The volatile memory (VS) may beRAM, organized as 8 bits wide with a clock rate of 125 MHZ. The storagecapacity of the RAM memory may be about 2 percent of the storagecapacity of flash memory (0.5 to 2 GB), with the addition of an area forerror correcting code (ECC).

The design in this example is consistent with the RAID architecturedisclosed in U.S. Ser. No. 12/079,737, so that erase operations on theflash memory have little or no impact on the read latency, and writeoperations at a rate of up to a substantial fraction of the maximumwrite bandwidth have little or no impact of the read latency. This ismerely an example of a design constraint that may be imposed. The datastructure and method is intended to facilitate recovery of the metadatafor the non-volatile storage on the module in the event of a crash.

For the purposes of this example, the following terms are used forconvenience in describing the memory addresses:

Basic Data Unit (BDU) which may be 2*512 byte sectors plus a spare dataarea; the “spare area” of a BDU refers to the spare area of both sectorsof the BDU considered as a single entity;

-   -   Quad Data Unit (QDU) which may 4*BDU or 4 Kbytes;    -   Octal Data Unit (ODU) which may be 2*QUU in adjacent memory        locations;    -   a block, which is a plurality of ODUs; and    -   2block which may be a address in memory formed by treating block        “i” and block “i+1” as a single block; the 2block is indexed as        2Block[i/2], where “i” is an even number.

Blocks may be described as containing one type of information, and thismay often be done to simplify the implementation or to make certainoperations more efficient, or to reduce the record keeping required byallowing some structures to be tracked on a block-by-block rather thanpage-by-page basis. However, this is not intended to be a limitation.For example, map table (MT) and block table (BT) checkpoints may storedseparately, but they could as well be stored in checkpoint blocks (CPB)containing both types of data. Log Blocks (LB) and data blocks arestored separately but the log could be stored in data blocks, or incheckpoint blocks. Root blocks (RB) and index blocks (IB) could bemerged, root blocks (RB) could be stored in arbitrary locations andfound by searching the spare areas for a special marker: similarly withindex blocks. Both root blocks and index blocks could be eliminatedentirely and the location of the checkpoint and log segments discoveredby searching for some identifying marker. So when a field or function isdescribed as being in a “block” of a certain type, the description couldbe read as a “page” of a certain type, or even “sector” of a certaintype depending on how finely the different data types are interleaved.

The primary addressable memory unit of this example data structure isthe BDU, and the spare area of the BDU may be considered to have beenaddressed when the corresponding BDU is addressed. Data in a BDU may notbe addressed as such, but may be extracted from the referenced BDU. FIG.6A shows the bit assignments in a typical index word, having a length of28 bits.

For purposes of discussion, Samsung part numbers K9KAAG08U0M throughK9NCG08U5M (Samsung, Seoul, Korea) are considered, each part having acapacity of 2 GB per chip select line. The physical memory address of asector in a 2Block is specified by bits 0-2 for the BDU, bits 3-8 forthe ODU, and bits 9-20 for the position in the 2Block, and Bits 21-23are for bus select. Bits 24-28 may be assigned to functions based on thespecific configuration of memory circuits used. Where 8 packages areused, then bit 24 or bits 24-25 may be used to provide for chipselection. Where 16 packages are used, then bit 24 may select betweenthe two packages on a bus, and bits 25-26 provide the clip selection asshown in FIG. 6B.

FIG. 7 shows the use of an index word to identify the memory location ofa specific BDU on a chip. The bit pattern of the index word locates theBDU as being BDU 2 of QDU 1 of ODU 62 of 2BLOCK 2049.

There may be several global variables on a system or module basis. Thesystem may have a counter with granularity of 1 microsecond and aroll-over time of 1 second. This may be used, for example, tosynchronize the erase and write operations of RAID columns. A moduleprogram sequence number (PSN or PgmSeqNum) having a length of 40 bitsmay also be used, which counts the operations actually performed. ThePSN may roll-over (wrap) perhaps every several weeks, depending on theclock rate. A background refresh operation may be needed so as tomaintain the stored PSNs to within 2̂38 of the most recent value of thePSN.

Each page (QDU) may have a spare area as shown in FIG. 8, where theauxiliary data is stored. The data area of the QDU is sized at 4096bytes, and the spare area at 16 bytes per sector. Since the BDU is theconcatenation of two sectors, the spare area allocated to a BDU is 32bits. One of these spare data areas, corresponding the sectors K and L,is shown in detail as representative of the other spare data areas. A 16byte area is provided for ECC to protect the integrity of the data areaand the spare area; the ECC may, for example, be divided into 2portions: one for the data and one for the spare area, so as to allowthe spare area to be read and verified without requiring the data to beread. In addition to, or in place of, ECC other data protectionalgorithms such as a CRC may be included, with differing coverageranges; for example, the 16 bytes may be split into 12 bytes of ECCcovering both data and spare area and 4 bytes of CRC covering the sparearea, so that if the spare area CRC verified the data of the spare areathe spare area data could be used without having to read the entire dataplus spare in order to perform ECC check of the spare area. In anotheraspect, the 16 bytes could be split into an ECC covering the data, anECC covering the spare area, and a CRC covering both areas. The PSN isstored as 5 bytes.

The block-type field stores an indicator that represents the type ofinformation stored in the block. This may be a hexadecimal number andassigned as follows:

0xFF=Root Block (RB)

0xF1=Index Block (IB)

0xF2=Block Table (BT) for Checkpointed Blocks (CB)

0xF4=Map Table (MT) for Checkpointed Blocks (CB)

0xF8=Log Block (LB)

0x0F=Data Block

0x00=Bad Block

Other bytes may be reserved. The contents of the Spare Area Fields, SAF0and SAF 1, depend on the block type, and are shown in FIG. 9.

Data structures relevant to the present example are shown in FIG. 10.Generally, the data structures in the flash memory (NVS) have acorresponding data structure in the RAM; however, there are several datastructures found in the RAM but which may not be found in the flash.When discussing data structures, the term “block” may be used to referto a logical data construct, each type of which may have different sizeand function. This use of the term “block” when used for a datastructure, needs to be distinguished from the term as used to refer tothe minimum erasable amount of contiguous memory of a flash chip, whichis also termed a block.

A Root Block (RB) is allocated to each flash package and there may be,for example, 8 or 16 flash pages comprising the memory module. In thisexample, two Index Blocks (IB) are allocated to each bus. The CheckpointBlocks (CPB) may be Block Table (BT) where there may be 32 BTs per 32 GB(32-512 block units. for example, 32 blocks to 512 blocks for a modulesize ranging from 32 GB to 512 GB+16 per module, and a Map Table (MT)where there may be 1K MTs per 32 GB (1K to 16 K)+16 per module. The MTsmay be about 0.8 percent of the total storage area. The +16 provides forthe situation that 32 BT CPB per 32 GB represents the actual number ofCPBs needed, but as the old check point block for a range of addressesis not overwritten prior to writing the new checkpoint block, at least 1more block is allocated than is needed to store the metadata. Having +16locations allows for contemporaneous transactions with all 16 packagesof a memory module. In the limit, only +1 block would be needed but theoperation may then be limited in the number of parallel writes and, as aresult, the rate at which checkpoint data may be written to NVS. For theBT, perhaps only one extra CPB may be needed.

The 1K per 32 GB Map Table (MT) size assumes one hundred percent of thedata is addressable by the user; that is, a circumstance where allpossible physical addresses in the memory could be filled with userdata. However, in this example, no more than about 99.2% of theaddresses could be used by the user, as about 0.8% of the chip memory isbeing used for the CPBs. Memory space is also needed for the log as wellas memory blocks reserved to allow for replacing other blocks which gobad over the life of the part. Data sheets for typical products suggestthat an allowance for failed blocks may be about 3%. Blocks may also beallocated for housekeeping operations such as garbage collection or wearleveling. So, the total user addressable space may be only 95% of thephysical memory in system with little or no space reserved so as toimprove performance attributes such as latency or write throughput. Insome circumstances, however, less than 50% of the address space may beavailable to for user data. While the user data space is reduced fromthe physical data space by these system needs, the location of user dataand system data in the physical memory may not be restricted to specificphysical memory locations, except for avoidance of bad blocks.

A Log Block (LB) stores the transactions, and there are approximately600 log blocks per 32 GB of memory. The number of LBs depends on thetotal amount of time to perform a full checkpoint of the CPBs, as thecheckpointed LBs need to extend backwards in time as far as the earliestof the still valid stored CPBs. If check point blocks are written to NVSat a fixed rate, then the approximate maximum memory size of the log isdetermined primarily by the number of BDU writes that can be performedduring the time taken to write a full checkpoint of the MT and BT tablesto the NVS. When the memory space available for the log is fixed, thespeed at which the checkpoints have to be written may be determined bycomputing how fast the log can be filled.

In an aspect, the speed of checkpointing may be varied so that when thesystem is mostly idle and few entries are being made in the log,checkpointing may then proceed more slowly.

In yet another aspect, the checkpoint can also be written based on howmuch data has been written to the log rather than how fast the log hasbeen written based on, for example, the ratio of the sizes of thecheckpoint region and the size of the log, so that a full checkpoint maybe performed before the full log area has been written with log entries.

The Data Blocks (DB) are the area for storage of user accessible data. ABad Block (BB) is a block which has been declared ‘bad’ for any reason.The bad blocks may be tracked for various reasons by keeping a list ofsuch blocks, in this case in the Root Block, such tracking is notrequired for operation of the system as the Block Table entry of theblock will also be marked bad which will prevent it being used to storedata.

The Root Block (RB) may conveniently be block 0 of a chip, althoughother locations may be used. This block may be infrequently programmedor erased after initialization, and is primarily devoted to recordkeeping with respect to the chip on which it is located. Suchinformation as the manufacturer information (manufacturing date,production lot, and the like), current position of the module in asystem and the memory package on the module, and metadata informationmay be stored. The RB metadata may comprise, for example, a list ofindex block (TB) addresses, the number of log and CPBs, and an initialbad block list. The root blocks (RB) point to the index blocks (IB). Theinitial bad block (BB) list may provide for initial bad blocks for eachpackage. The initial bad block list may be only for the memory blockslocated in the same package as the root block, while subsequent badblock lists may contain addresses for memory blocks located anywhere inthe module.

The Root Block record (RBR), shown in FIG. 11 may have a fixed-sizeheader of 76 bytes, and the remainder of the first BDU may containinformation such as manufacturing information, such as a serialnumber/lot number/date of manufacture, information about othercomponents on the module; relatively static information such as thelocation of the module in the system, and a system ID number identifyingthe specific system in which the module has been installed so that ifthe module is removed from the equipment and installed in a differentsystem the module can be detected as belonging to a different system, sothat the module data is not unintentionally used or overwritten

The remaining BDUs of the QDU may contain information relating to badblocks. The bad block records may begin with a count of the number N ofbad blocks, followed by the addresses of the first 254 bad blocks. Thelist of bad block addresses may continue into the next BDU if N isgreater than 254, else the remainder of the BDUs in the QDU are eithernot written, or zero filled. To change the data for the index blocks, orto add new bad blocks, a new RBR is written, typically at the end of thepreviously recorded RBR. The new RBR may start on a QDU lower boundary,although this is not required.

The Root Block (RB) may also have a spare area that may be similar tothe spare areas for other BDUs, and is shown in FIG. 12. The type fieldvalue is 0xFF, and any other type value indicates a bad block. Two ofthe areas that were shown as reserved in FIG. 11 are used in the RB. Asame 24 bit RBR sequence number SAF0 is assigned to all of the BDUs inthe same RBR, and a 24 bit erase block count (EBC) SAF 1 is assignedsuch that all programmed pages in a RB have the same EBC. The RBR of theRoot Block (RB) written to a new RB if there is no more space in theblock to write the new version of the RBR. When updating is due to achange in index blocks (TB), all of the Root Blocks (RB) may need to beerased. No new RBRs are appended to the RB after the last valid RBR;however, if there is not enough space to store a new entry, then the RBwill have to be erased. If all of the RB were to have been erased at thesame time, and the power failed, then there would be no valid RB to bootfrom. The number of RB that may be erased thus may depend on the policyused for selecting a valid RBR from which to boot. If the policy is topick the single most recent valid (error free) RBR then, so long as oneRB remains, the system may be booted without a more complex recoveryscheme. In an aspect where the policy is that there must be at least Nvalid RBR that are identical, then at least N RBs must remain un-erasedwhile writing new RBRs to an erased RB.

Index Blocks (IB) 0-7 point to the location of Block Tables (BT) andCheckpoint Blocks (CPB), while IB 8-15 point to Map Table (MT) blocks.The Index Block (IB) spare area is shown in FIG. 13. The configurationis similar to the RBR spare area in that the field type is 0xF1signifying an IB, and the variable SAF0 comprises a two-bit type fieldand a 22 bit IBR sequence number. All segments in the same IBR have thesame sequence number. The SAF1 is an EBC similar to that in the RBR. The2-bit type field indicates the type of index data the index block pointsto: BT (00); (01) LB record; and, MT record (MT).

Each memory block has a size of 256 KB; however, as described above, apair of memory blocks may be combined to form a single 512 KB block soas to permit dual-plane operation. Such a configuration takes advantageof specific architectural features of existing mass market components,and is not a requirement of the design. This configuration thus has 5121 KB BDUs on each pair of chips. Each block has a spare area and theparticular features of the block spare area are shown in FIG. 14, wherethe type field is 0x0F. In this example, the value of SAF0 is a 30-bitlogical BDU index and a 1 bit Seq# set field.

The Seq# set field may be used when the sequence number is set to valuedifferent than a value one greater than the last sequence number for thelogical address. Such a circumstance could occur in the case of RAIDreconstruction into a spare module where the spare module has onlyinitialized values for sequence numbers, or where a module has lostsynchronization with the other modules of a RAID group. This may occur,for example, when a power failure occurs after some, but not all, of themodules had had new data written to NVS. For example, if only one moduleof a RAID group had had written data to NVS, then the write operation ofthe RAID group would not have been completed. The previous data valueswould have to be restored, either by, for example, recovering the olddata by finding the locally on the module, or being reconstructing thedata using data from the other members of the RAID group. Theseoperations may now have stored at least two instances of data for agiven logical address in the NVS: one instance with a smaller Seq# but alater PSN; and, one instance with a larger Seq# but an earlier PSN.Should the power fail prior to writing the relevant metadata to NVS thismay result in incorrectly subsequently recovering the state of the NVS:the location with the larger Seq# may be incorrectly assumed to be themost recent version. A Seq# set bit indicates to the recovery processthat determination of the most recent of the entries by comparing the(smaller) Seq#s may not be correct; but, rather, the recovery operationmay proceed, for example, by comparing (larger) PSNs. However, since thePSN for a given entry was not stored in RAM, this comparison may be madeby reading the entry in NVS which is currently considered the mostrecent, so as to compare it to the entry which was found during therecovery portion of booting.

The SAF1 field is a structure in the NVS which contains the contents ofthe second half of the MTE stored in RAM: the State+SN portion. Thefirst part of the MTE in RAM may not need to be stored in the NVS as thefirst portion contains the physical address in NVS at which the LBA isstored, and which is known from the SAF1 field being read.

When the system is re-started after a clean shut down, the incrementallystored checkpointed metadata, stored in the NVS, represents the lateststate of the memory, and correctly points to the location of data of LBAstored in a physical memory location, as there was sufficient time toupdate all of the checkpointable metadata in RAM using the volatile log,and to store a complete version of the updated metadata as thecheckpointed metadata in NVS. Alternatively, when a clean shutdown isperformed by storing the recent log file segments rather than thecomplete metadata, the metadata stored in NVS and read to VS is updatedby the stored log data. However, as previously described, a “dirty”shutdown may result in an incomplete image of the current dynamicmetadata, and volatile log data and the “lost” data needs to be“discovered”, using the techniques previously described.

A Map Table Entry (MTE) may be a 64 bit word, as shown in FIG. 15 where32 bits are allocated to the LBA location address and 32 bits areallocated to serial number and state information. The location datapoints to the address of the data in the flash memory, when the MT isthe MT in the NVS; or, when the MT is the cached MT, the location datapoints to a cached BDU descriptor, which contains the flash memoryaddress. The MTE word location field is further described in FIG. 16 forcircumstances where the BDU is in flash (V0) or in DRAM (V8). V12 may beused to avoid having to write data to NVS which is comprised of somefixed pattern, such as all 1's or all 0's, common test patterns such as0xf0, 0x5a, or the like. In this situation, the type field informs theinterpretation of the pattern field.

In an aspect, when the pattern is a simple repetition of the same 2bytes, then the value of the type field would indicate to use thepattern field directly. In another aspect, when the pattern in the datawas some well known filler pattern such as 0xdeadbeef, 0xfeedface, orthe like, then the value of the type field would indicate that thepattern field was an index into a predetermined table of such patterneddata, or the pattern field may be an index into some dynamic table oflearned patterns. Other type descriptors (e.g., V14 and V15) may bereserved. The MTE location field as used in the flash is shown in FIG.17. The logical BDU address is 1 bit larger than the physical BDUaddress so that two address spaces may be accommodated.

When used with the log and the CPBs committed to NVS, the MTE locationfield may be any of the values used in the volatile memory (VS)versions, except for V8, which refers to the DRAM location. If the MTElocation filed is V8, then the indicated cache descriptor needs to bede-referenced so as to determine the in-NVS state of the BDU, and thelocation field corresponding to the in-NVS state of the BDU is thatwhich is placed in the log or CPB, as appropriate. By de-referencing thepointer, the data at the address value which the pointer points to isread, rather than the value of the pointer itself, which is the dataaddress value.

The MTE state and sequence number (SeqNum) fields are shown in FIG. 18.A 20-bit SeqNum is used. A 4-bit behavior predictor may be allocated toeach of 3 behavior predictors. The Read (P-R) predictor may be used toindicate the likelihood that other BDUs in an ODU will be read if thepresent BDU is read. The Write (P-W) predictor may be used to indicatethe likelihood that other BDUs in an ODU will be written if the presentBDU is written. And, the Lifetime (P-L) predictor may be used toindicate the likelihood that the BDU will be re-rewritten to the NVSbefore the flash version of the data is moved during a garbagecollection operation.

FIGS. 20 to 25 show the various types of data entries in the log,denoted by the type field of the entry, which is stored in bits 29-31.

Type 1 is a Map Table Entry update shown in FIG. 20, and may be usedwhen a BDU is written to NVS; Word ‘A’ contains the physical address ofthe previous location of the BDU; Word ‘B’ contains the Logical Addressof the BDU; and, Words ‘C’ and ‘D’ contain the contents of the VS MTentry for this BDU.

Type 2 is a Block Write log entry, shown in FIG. 21, which may be usedto record a write to NVS of metadata rather than ‘user’ data. Word ‘A’may contain the PBI to which the write was performed, and the rest ofthe entry has various fields such as the type of the block, the PSN ofthe BDU, and may contain other data either for redundant checking, or tosupport the housekeeping and management functions.

Type 3 is a Block Erase log entry, shown in FIG. 22, which may be usedto indicate the completion of a block erase. Word ‘A’ is the address ofthe first BDU in the block; the ‘O’ field in word ‘C’ is the type of theblock being erased as a redundant error check; and, the PSN is the valueof the PSN when the block erase was performed.

Type 4 is a Block Assign log entry, shown in FIG. 23, which may be usedwhen the type of a block is changed; it is the same as a Type 3 entrywith the addition of the ‘N’ field containing the new type of the block,and the index field in word ‘B’ which is used if the block is beingassigned to be a checkpoint block to indicate the position of the blockin the circular checkpoint buffer.

Type 5 is a Bad Block log entry, shown in FIG. 24, which may be usedwhen a block is declared bad. The index field in word ‘B’ contains thelocation in the block of the error that caused the block to be declaredbad.

Type 0 is a Pad log entry, shown in FIG. 25, which may be used to fillunused space in a log BDU when it is desired to write log BDU to NVSbefore the log BDU is full of data, such as on a system shut down, orafter the writing of an entry into the log that is desired to havecommitted to NVS immediately: such as, a bad block entry.

The terms “garbage collection” and “wear leveling” are used togenerically describe housekeeping operations that are performed in flashmemory systems. Garbage collection relates to the processes ofreclaiming “dead” memory locations created by the writing of data to aLBA located in the flash memory. The source data location in physicalmemory now contains out-of-date data and represents wasted space whichneeds to be reclaimed, so that an appropriate amount of free memory ismaintained to permit continued write operations. Wear leveling generallyrelates to the processes of moving data in the flash memory so as toattempt to keep the number of memory block erase operationsapproximately equal over the blocks of the memory, so as to avoidpremature wear out of the flash memory. Presently, flash memory circuitsare rated by the manufacturers as having a lifetime which may bemeasured in the number of erase operations before failure. This is inaddition to any conventional time-related failure-rate specificationwhich may be given.

The sequence number SeqNum may be incremented every time a change ismade to the BDU, regardless of whether this new BDU is committed to theNVS. The SeqNum may be used during the recovery from a “dirty” shutdown,however caused. Where RAID storage techniques are used, the SeqNum maybe the same across all of the BDUs of a RAID group, wherever stored.When the data is returned from the various memory locations of a RAIDgroup (which may be, for example, chips, circuit packages, or modules),all of the data in a RAID group that belonged to the same writeoperation will then have the same SeqNum.

The BDU, in this example, comprises 1 KB of data, and associatedauxiliary data. The SeqNum may be returned on the same data path as thedata when performing a read operation. The SeqNum may also be returnedon this data path, for example, when acknowledging (acking) the receiptof data that is to be written to memory.

The SeqNum may be set at the time that the command to write the 1 KBdata of the BDU to the NVS is issued. A use of the SeqNum may be torebuild and to resynchronize the memory locations of a RAID group ifthey become inconsistent, a situation which may obtain during a dirtyshutdown. The SxS bit in the location field may be set until the MTE hasbeen checkpointed to NVS, so that the associated SeqNum will not bere-used during the recovery process.

A 2block is comprised of 512 BDUs for which the following informationmay be available: the state; a 64-bit BDU live status bit map; thenumber of free BDUs, and the number of live BDUs, represented by 2 byteseach; the PSN of the CPB, represented by 5 bytes; a 3 byte erase count;a 3 byte read count; an error count [max_bits] 3 bytes/1 byte; and, anaverage programming time (3 bytes). Max_bits represents the largestnumber of bits which were detected as being in error by the ECC at anyone time. Since the ECC can only correct a certain number of errors, itmay be useful to know how many error bits have been encountered so thatthe data can be moved to a new memory location before the number oferror bits is to large to be corrected by the ECC. Other data that maybe useful to record may be the average erase time, and the maximum timesfor programming and erasing, which may vary over the life of the part.

Two types of Checkpoint Blocks (CPB) may be used: a Block Table (BT) CPBand Mapping Table (MT) CPB.

The BT-CPB may have 8 entries for each BDU, and 64 entries for each ODU.Each data block may contain 512 BDU, so a BDU in the BT-CPB containing 8entries checkpoints the BT structures representing 4K data BDUs, holding4 MB of data, and the 64 entries in an ODU hold the BT structuresrepresenting 32K data BDU or 32 MB of data. The Block Tables (BT) may becheckpointed into the NVS on a periodic basis during normal operation.For example, 20 ODU BTs, representing 1280 2Blocks may be checkpointedinto NVS each second. During a normal shutdown, the BTs in volatilememory may be checkpointed into memory at a faster rate until all of theBTs have been checkpointed.

Where the BTs are periodically checkpointed as described above, a fullcheckpoint of the BTs is approximately proportional to the memory sizebeing managed. For example, at the rate of checkpointing stated above, afull checkpoint of BTs for a 32 GByte memory may be performed every 50seconds. The time to checkpoint larger memory systems would beproportional to the amount of memory in the system so that, for example,a 512 GB memory system would be checkpointed in 13 minutes.

A Map Table CPB may, for example, contain 128 entries per BDU, and 1Kdata entries for each ODU, and 160MT ODU may be checkpointed eachsecond. Thus, a full checkpoint of the MT CPBs may be performed in 204seconds for a 32 GB memory, and a 512 GB memory would be checkpointedevery 54 minutes.

Each checkpoint block spare area may have additional information, asshown in FIG. 20D, where a field type byte indicates the type of CPB,and 0xF2 indicates a BT CPB and 0xF4 indicates a MT CPB. Further, thevariable SAF0 is an index of the first entry in a BDU, and SAF1 may bethe block erase count.

The Map Table (MT) provides for the memory addressing information.Secondary tables (one per 128 MTEs) may contain “active” descriptors anda PSN. The “active” descriptors may indicate how many of the MTEs in therange [128*i, 128*i+127] and have a type V8 location field, where thedata is in volatile memory (e.g., RAM) and will have to be de-referencedwhen being checkpointed. The PSN[i] of the CPB containing MTEs in therange [128*i, 128*i+127] can be used for log replay sequencing during asystem recovery.

The Log Block (LB) is comprised of 16 byte entries so that there are 256entries for each BDU of the LB. All entries in a BDU should be filled,so as to avoid ambiguities. As such, padding entries may be used toprogram unused memory locations in the BDU during shutdown, or where animmediate write of the BDU to NVS may be desired, such as when a badblock entry is made. The LB entry types are: MTE (0x1); CPB write (0x2);block erase (0x3); block assign (0x4); bad block (0x5); and notprogrammed (0x7). The indicator 0x6 is reserved.

The LB entry representing a MTE is shown in FIG. 20. Word A may be thephysical location of the BDU prior to the programming (write) actionresulting in this LB entry. Word B may be the index of the logical block(LBA) that is being written. Words C and D are the MTE for the LBA beingwritten. Thus the LB entry links the previous physical memory locationof a LBA with the new physical memory location of the LBA.

When a CPB is being written, the LB entry is as shown in FIG. 21. Word Ais the physical location of the CPB BDU that is being written; word B isthe index value of the first entry in the BDU, which may be used as avalidity check to determine that the correct data is being read (anyother check data may be substituted, such as a CRC over the BDU, or maybe omitted depending on the data reliability requirements of thesystem); word C contains a one byte type field, and the first byte ofthe PSN; and, word D contains the last four bytes of the PSN associatedwith the CPB BDU.

The LB entry representing a block erase operation is shown in FIG. 23.Word A is the index value of the first BDU in the block of NVS beingerased (another check data may be substituted, such as a CRC over theBDU, the PSN of the first BDU, or the like; these values allow aconfirmation that the block was erased by determining that the currentdata does not match the check data, thus indicating that the old,pre-erase, data has been replaced); word B is reserved; word C has asingle byte indicating the type of block that was erased, and the firstbyte of the PSN; and, word D has the last four bytes of the PSN.

As mentioned above, in this example, but not as a limitation, each blockmay contain one type of data: index, log, checkpoint, or user data.While this may indeed be the result of a specific design, the limitationhere is made so as to merely to simplify the presentation.

The LB entry for a block assignment operation is shown in FIG. 24. WordA is the index value of the first BDU in the block; word B is the indexvalue of the first entry in the block (if applicable); word C has onebyte representing the new block type, one byte representing the oldblock type, and the first byte of the PSN; word D has the last fourbytes of the PSN.

The LB entry for a bad block is shown in FIG. 22E. This entry is madetwo times. The first entry is made when a bad block is detected. Theremainder of the LB is then padded to completion, and written to NVSimmediately. Once all of the BDUs in the bad memory block have beenrelocated another entry is made. The entry may differ in that the firstentry uses the current block type as the block type, while the secondentry uses the bad block type as an indicator. Word A is the index valueof the first BDU in the bad memory block; word B is the index value ofthe faulty page if the defect is a page program (write) failure, and all“1” if the defect is a block erase failure. Read errors are ‘normal’when currently available flash memories are used and are corrected bythe ECC; the number of errors may be stored in the block table. Blocksmay not declared bad because of read errors, but as a result of programor erase errors. Word C contains the one byte block type indicator andthe first byte of the PSN; and, word D contains the last 4 bytes of thePSN.

The LB entry during a pad operation is all zeros, as shown in FIG. 25.This permits a fixed content ODU to be rapidly written to the NVS. Withthe NVS memory circuit being used in this example, this permits an ODUto be padded in about 25 us, rather than about 400 us when a write isperformed over the bus.

The LB spare area is shown in FIG. 22. The unique aspects of the LPspare area are that the type field is 0xF8 indicating that this is a LB;the value of SAF0 is the number of entries in the LB; and, the value ofSAF1 is the block erase count.

Having established the data structures and performed the operations forcheckpointing the metadata and log to NVS, a recovery or restart can beperformed from the point of shutdown, or from the point of the crash, ifthe shutdown was dirty.

When the system is initialized, reset, or otherwise restarted, the MTand the BT are read from the NVS (e.g., flash) to the volatile storage(e.g., RAM), and the location (LogStart) of the log block address (LBA)having the smallest PSN greater than the smallest PSN of any entry inthe MT or the BT is determined. any Entries in the log with a PSNsmaller than all of the entries in both the MT and BT tables of thelatest checkpoint are not needed for recovery the previous transactionswere fully reflected in the MT and BT that were read from NVS, the logrecovery starts at the location (LogStart) of the BDU in the log havingthe smallest PSN greater than the smallest PSN of any entry in the MT orthe BT.

Aspects of the process for this example may be described in pseudocodeas:

  L = LogStart      While (L!=NULL) & (L.PSN >= LogStart.PSN) {       /*while the Log BDU pointed to is not NULL (not erased) and the PSN of theBDU is larger than (that is, more recent than) the PSN of the beginningof the log, process the entries in the BDU: since the Log is circular,as L moves along the log L will eventually wrap around and, if the BDUpointed to had not been erased, the BDU will have an earlier PSN thanthe beginning of the Log and this will indicate that the whole log hasbeen processed */        For I = 0 to 63         If L.E[I].Type != 0Process_LE(L,I) /* process any non-pad entries */       L=NextLogEntry(L) /* advance to the next BDU of the Log, when the end of aLog Block is reached find the next Log Block and start at the beginningof that block. This step assumes that the log is written sequentially,one block after another; however, for example, if the log had beenstriped across more than one block at a time, or otherwise written in amanner which steps through the memory sequentially one block at a time,then NextLogEntry would advance according to the layout policy that wasused. */       }  Process_LE(L,I){   E = L.E[I];   T = E.PSN  Switch(L.E[I].Type){    Case MTE:  /* Handle a change in location of adata BDU,*/     /* extract the various fields of the log entry     OldLoc is the physical location the BDU was in before this update,if the BDU was not previously used, or had been stored only as a patternin the MT then the OldLoc would be set to an invalid address such as 0     NewLoc is the location the BDU is being written to, if the BDU isnot being written to NVS for some reason such as being deallocated orbeing saved as a pattern in the MT then NewLoc would be set to invalidaddress such as 0      LBI is the Logical Index of the BDU being writtenthat this entry refers to */     OldLoc = E:Bits[0-28];     NewLoc =E:Bits[64-92];     LBI = E:Bits[32:60];     /* get the Block Tableentries for the new and old locations of the BDU */     OB = BT[ (OldLoc/ BlockSize)]     NB = BT[ (NewLoc / BlockSize)]     /* if the new orold location of the BDU was in NVS, and the Block Table entry in NVS isolder than the log entry then add or remove that entry from the inmemory BT data structures, and perform whatever other processing isappropriate, such as moving the block to the free list if it is empty orremoving it from the list of blocks available to be written to if it isfull, etc */     If (OldLoc != 0) & (T > OB.PSN) { Remove(OB, OldLoc) }    If (NewLoc != 0) & (T > NB.PSN) { Add(NB, NewLoc) }     /* if thePSN in NVS of the MT containing the BDU is older than the log entry,update the in-memory MT by setting the PSN based on data in the logentry */     If T > PSN[LBI/128] {      MT[LBI]= E:Bits[64-127]}     }    Break;   Case Block_Write:     /* May be used to simplifyhousekeeping, for example, by indicating that required updates fromchanging the type of a block, such as updating of an Index Block topoint at block which was just allocated to be a Log Block were writtento NVS so that it is not necessary to inspect the Index Block to see ifit was updated. In general this may be used anytime confirmation of awrite to the NVS is required or is helpful */     Break;   CaseBlock_Erase;     B=E:Bits[0:27]; /*Index of block being erased */     If(T > BT[B].PSN) { /* block was erased after its BT entry was checkpointed */      Process_Block_Erase(B); /* handle all data structurehousekeeping usually performed after a block erase, clear the live bitfield, increment the erases count, move the entry to the free list, etc*/     Break;   Case Block_Assign;  B=E:Bits[0:27]; /*Index of blockbeing assigned */     If (T > BT[B].PSN) { /* block was assigned a newtype after its BT entry was check pointed */     Process_Block_Assign(B); /*handle all data structure housekeepingperformed after the type of a block is changed, may involve adding orremoving the block from various lists. If the block was changed to orfrom a Check Point Block or Log Block then the Index Blocks (if used)may need to be updated. If the block was changed to or from an IndexBlock then the Root Blocks (if used) may need to be updated. A checkshould be performed to see if the block already was updated */     } Break;  End Switch;

The pseudocode above is but one of many such process detail fragmentswhich may have been given to explain aspects of the example and is notintended to be limiting.

After processing of the log, the location of the last data written intoeach block as of the writing of the log will be determined; then eachblock is checked to see if there is additional data present that waswritten after the last log entry. If BDUs are found that are more recentthan the entries stored in the MT for the LBA of the discovered BDU,then MT is updated to reflect the new location of the data, and the newand old BT entries are updated accordingly. In the case that thesequence number set flag is set in the discovered BDU then the MTEsequence number may not be used to determine which BDU is more recent,the discovered one or the one currently pointed to by the MT entry forthat LBA, and the PSNs of the BDU in NVS representing the same LBA haveto be compared to determine which data is more recent. If the size ofthe PSN is small enough that the PSN could wrap around during thelifetime of the storage system then some form of scrubbing should beemployed to move BDUs whose PSNs are old enough that there is apossibility of being unable to correctly determine the relative age ofdifferent BDUs having data for the same LBA during a recovery operation.

It is therefore intended that the foregoing detailed description beregarded as illustrative rather than limiting, and that it be understoodthat it is the following claims, including all equivalents, that areintended to define the spirit and scope of this invention.

1. A method of operating a memory system, the method comprising;assigning a sequence number to each data element for determining thelatest version of the data element; and setting a flag to indicate whenthe sequence number is not valid for use.
 2. A method of operating amemory system, the method comprising: creating metadata representinginformation relating a data element stored in a memory, the metadatahaving a field having an address where the data element is stored; andreplacing the address data with a flag when the data element is a knowndata pattern, the flag indicating the data pattern.
 3. A method ofrecovering metadata for data stored in a FLASH memory system, the methodcomprising: using a computer to maintain block metadata representing avalue of a physical page location of data in a block of non-volatilememory (NVM), wherein data and page metadata is stored in physical pagesof the block, written in monotonically increasing order, and the blockmetadata includes a value corresponding to a highest physical pagelocation P in the block that has been written with data and pagemetadata; performing block metadata recovery by reading page metadata inthe physical page location of the block having a value of P+1, where P+1is less than or equal to the maximum page number of the block, and: ifthe page metadata read from the physical page location having a value ofP+1 does not contain valid page metadata, performing block metadatarecovery for another block of NVM; or if the page metadata read from thephysical page location having a value of P+1 contains valid pagemetadata, storing the valid page metadata read from the physical pagelocation to a recovery log; and incrementing the value of the physicalpage location by unity, and repeating the step of performing blockmetadata recovery until the occurrence of one of: a next higher physicalpage location does not contain valid page metadata; or, the value of theincremented physical page location is equal to the maximum page number;and performing block metadata recovery for another block of NVM untilall of the blocks of NVM in which data and page metadata has been storedin physical pages have been processed.
 4. The method of claim 3, furthercomprising processing the recovery log to determine a sequential orderin which the recovered valid page metadata of a logical page was writtento the block of NVM.
 5. The method of claim 3, further comprisingupdating the block metadata using the recovered valid page metadata toperform the steps of: adjusting the value P of the highest physical pagelocation for each block to the value of the highest physical page numberdetermined to have valid page metadata in the step of performingmetadata block recovery; and using the valid page metadata stored in therecovery log to update the block metadata so that a logical blockaddress corresponds to a current physical page address.
 6. The method ofclaim 3, further comprising determining a most current physical pageaddress corresponding to a logical block address of valid page metadatain the recovery log by comparing sequence numbers in the valid pagemetadata of two physical page locations that reference a common logicalblock address, wherein the sequence numbers are have been assigned inmonotonic order when the data of the data and metadata associated with alogical block address is written to the physical page location and thelogical block address corresponding to the highest of the comparedsequence numbers is selected.
 7. The method of claim 3, furthercomprising: determining that page P+1 does not contain valid pagemetadata; determining that page location 0 does not contain valid pagemetadata; and if the page locations P+1 and 0 do not contain valid pagemetadata, identifying the block as an erased block.
 8. The method ofclaim 3, where valid page metadata is page metadata that is consistentwith the data stored in the physical page with which the page metadatais associated.
 9. The method of claim 3, wherein the recovered metadatais stored in NVM.
 10. The method of claim 9, where the recoveredmetadata is used for updating a checkpointed copy of the metadata inNVM.
 11. The method of claim 3, wherein valid page metadata stored inthe physical page of the NVM comprises an error correcting code for thedata stored in a same physical page.
 12. The method of claim 11, whereinthe valid page metadata comprises a logical block address in the blockmetadata associated with the value of the physical page address at whichthe data is stored.
 13. The method of claim 3, wherein when the data isstored in a RAID format, the valid page metadata for each chunk of dataof a RAID stripe contains a common sequence number.
 14. The method ofclaim 7, wherein the sequence number is a time stamp.
 15. The method ofclaim 7, wherein the sequence number is a counter value.
 16. The methodof claim 7, wherein the sequence number is unique to the FLASH memorysystem.